
#ifndef _TTG_PIPELINE_WISE_TASKS_
#define _TTG_PIPELINE_WISE_TASKS_
#include "Common/Definitions.h"

#include "Common/Structures.h"
#include "Runtime.Low/Threads.h"
#include "Runtime.Low/Devices.h"

namespace ttg
{
	namespace services
	{
		//Represents tasks with additional info for wise task scheduling.
		class WiseTask :public ttg::threads::Task
		{
			private:
				double t_expected;
				double t_start;
				double t_elapsed;
				ttg::structures::Loopback<WiseTask *> on_finish;
				ttg::devices::LogicalDevice selected_device;
				ttg::devices::LogicalDeviceMap<ttg::structures::InvokableObject *> task_kernels;
			public:
				//Creates task with given time difficulty.
				WiseTask(double expected_time);
				//Returns expected time difficulty (in seconds).
				inline double getExpectedTime() const
				{ return t_expected; }
				//Returns time of start (in seconds).
				inline double getStartTime() const
				{ return t_start; }
				//Returns elapsed time (in seconds).
				inline double getElapsedTime() const
				{ return t_elapsed; }
				//Sets selected device.
				inline void selectDevice(devices::LogicalDevice type)
				{ selected_device = type; }
				//Returns selected device.
				inline devices::LogicalDevice getSelectedDevice(void) const
				{ return selected_device; }
				//Adds kernel to current task.
				//Note: all kernels will be deleted by destructor.
				inline void addKernel(ttg::devices::LogicalDevice type,
									  ttg::structures::InvokableObject *kernel)
				{ this->task_kernels[type] = kernel; }
				//Returns collection with available kernels.
				//Note: all kernels will be deleted by destructor.
				inline ttg::devices::LogicalDeviceMap<ttg::structures::InvokableObject *> &getTaskKernels()
				{ return task_kernels; }
				//Task member. Contains implementation of task performing.
				virtual void perform(std::vector<ttg::threads::Task *> &produced_tasks);
				//Returns event, that will be rised after task performing.
				//Event arg == elapsed time.
				inline ttg::structures::Loopback<WiseTask *> &onFinish()
				{ return on_finish; }
				virtual ~WiseTask();
			friend class TaskScheduler;
		};
	}
}

#endif
